package ui.swing.scrolling;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

public class HeaderDemo extends JFrame {

	private static final long serialVersionUID = 8218820971555620470L;

	public HeaderDemo() {
		super("JScrollPane Demo");
		ImageIcon ii = new ImageIcon("xx.jpg");
		final JLabel lbl = new JLabel(ii);
		JScrollPane jsp = new JScrollPane(lbl);

		JLabel[] corners = new JLabel[4];
		for (int i = 0; i < 4; i++) {
			corners[i] = new JLabel();
			corners[i].setBackground(Color.yellow);
			corners[i].setOpaque(true);
			corners[i].setBorder(BorderFactory.createCompoundBorder(
					BorderFactory.createEmptyBorder(2, 2, 2, 2), 
					BorderFactory.createLineBorder(Color.red, 1)));
		}
		
		JLabel rowheader = new JLabel() {
			Font f = new Font("Serif",Font.ITALIC | Font.BOLD,10);
			public void paintComponent(Graphics g) {
				super.paintComponent(g);
				Rectangle r = g.getClipBounds();
				g.setFont(f);
				g.setColor(Color.red);
				for (int i = 30-(r.y % 30);i<r.height;i+=30) {
					g.drawLine(0, r.y + i, 3, r.y + i);
					g.drawString("" + (r.y + i), 6, r.y + i + 3);
				}
			}
			public Dimension getPreferredSize() {
				return new Dimension();
			}
		};
	}

}
